cmake_minimum_required(VERSION 3.27)
# msvc 支持utf-8,解决控制台乱码
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/source-charset:utf-8>")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fexec-charset=GBK")
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -fexec-charset=GBK")

#-DCMAKE_TOOLCHAIN_FILE=C:\software\vcpkg-2024.01.12\scripts\buildsystems\vcpkg.cmake
project(study_test)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

message(STATUS "Current C++ standard: cxx_std_${CMAKE_CXX_STANDARD}")
# 设置git命令和参数
set(GIT_COMMAND git)
set(GIT_PARAMETERS log -1 --pretty=format:"author is %cn , committed hash is  %H  , time is %ai ")

execute_process(
        COMMAND ${GIT_COMMAND} ${GIT_PARAMETERS}
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        RESULT_VARIABLE GIT_RESULT
        OUTPUT_VARIABLE GIT_INFO
        ERROR_VARIABLE GIT_ERROR
        OUTPUT_STRIP_TRAILING_WHITESPACE
)
# 检查git命令是否成功执行
if (NOT GIT_RESULT EQUAL "0")
    message(FATAL_ERROR "Failed to execute git: ${GIT_ERROR}")
endif ()
# 打印git提交哈希值
message(STATUS "Git commit info: ${GIT_INFO}")
add_definitions(-DGIT_INFO=${GIT_INFO})

find_package(Protobuf CONFIG REQUIRED)
find_package(RdKafka CONFIG REQUIRED)
find_package(redis++ CONFIG REQUIRED)
find_package(unofficial-mysql-connector-cpp CONFIG REQUIRED)
find_package(GTest CONFIG REQUIRED)
find_package(asio CONFIG REQUIRED)
find_package(nlohmann_json CONFIG REQUIRED)
find_path(REFL_CPP_INCLUDE_DIRS "refl.hpp")
find_package(cppzmq CONFIG REQUIRED)
find_package(gRPC CONFIG REQUIRED)
find_package(proxy CONFIG REQUIRED)
##find_package(RTTR REQUIRED)

add_subdirectory(asio_demo)
add_subdirectory(json_demo)
add_subdirectory(kafka_demo)
add_subdirectory(standard_demo)
add_subdirectory(protobuf_demo)
add_subdirectory(zeromq_demo)
add_subdirectory(grpc_demo)
add_subdirectory(proxy_demo)

add_executable(test_time_file test_time_file.cpp)

add_executable(test_redis test_redis.cpp)
target_link_libraries(test_redis PRIVATE redis++::redis++)

add_executable(test_mysql test_mysql.cpp)
target_link_libraries(test_mysql PRIVATE unofficial::mysql-connector-cpp::connector)

add_executable(test_google_test test_google_test.cpp)
target_link_libraries(test_google_test PRIVATE GTest::gtest GTest::gtest_main GTest::gmock GTest::gmock_main)

add_executable(test_cast test_cast.cpp)

